import 'package:flutter/material.dart';

class DoubleTitleAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String topTitle;
  final String bottomTitle;

  DoubleTitleAppBar({required this.topTitle, required this.bottomTitle});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue, // 自定义AppBar的背景色
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            topTitle,
            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
          ),
          SizedBox(height: 4), // 上下标题之间的间距
          Text(
            bottomTitle,
            style: TextStyle(fontSize: 14, color: Colors.white),
          ),
        ],
      ),
      padding: EdgeInsets.all(16.0), // 调整标题的内边距
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight * 2); // 自定义AppBar的高度
}

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: DoubleTitleAppBar(
        topTitle: "上层标题",
        bottomTitle: "下层标题",
      ),
      body: Center(
        child: Text('Hello World'),
      ),
    ),
  ));
}
